package com.company.exam12;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 第12题  通过JDBC读取员工表与部门表并显示出员工编号、员工姓名、职位、薪资、所在部门名称。（10分）
 */
public class test12 {
	public static final String DB_DRIVER="oracle.jdbc.driver.OracleDriver";
	public static final String DB_URL="jdbc:oracle:thin:@localhost:1521:XE";
	// orcl 表示Oracle数据库安装的实例名，默认是orcl，如果不是默认，则改成自己的
	public static final String DB_USER="scott";
	public static final String DB_PASS="a123456";

	public static void main(String[] args) {

		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			Class.forName(DB_DRIVER); // 加载驱动
			conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);// 获取连接对象
			String sx = "select * from emp";
			pstmt = conn.prepareStatement(sx);
			rs = pstmt.executeQuery();

			while (rs.next()) {
				int EMPNO = rs.getInt(1);
				String ENAME = rs.getString(2);
				System.out.println(EMPNO + "," + ENAME);
			}

			rs.close();
			pstmt.close();
			conn.close();// 关闭连接对象

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}


}
